package com.own.core.html.panel.link;

import java.util.HashSet;
import java.util.Set;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import com.own.core.html.component.link.OwnAjaxLink;
import com.own.core.html.form.Label.OwnLabel;
import com.own.core.html.panel.OwnPanel;
import com.own.util.CssImageUtil;
import com.own.util.listener.OwnListener;

public class OwnAjaxLinkPanel extends OwnPanel {

	OwnAjaxLink link;
	OwnLabel label;

	Set<OwnListener> listenerSet = new HashSet<OwnListener>();

	public OwnAjaxLinkPanel(String id, IModel model) {
		super(id, model);
		label = new OwnLabel();
		label.setDefaultModel(model);
		link = new OwnAjaxLink() {
			@Override
			public void onClick(AjaxRequestTarget target) {

				for (OwnListener ownListener : listenerSet) {
					ownListener.execute(target);
				}
			}

		};

		add(link);
		link.add(label);

	}

	public void setCssClass(Class cls) {
		if (cls == null) {
			return;
		}

		link.add(new AttributeModifier("class", true, new Model(CssImageUtil
				.getCss(cls))));
		label.setDefaultModel(new Model(""));

	}
	
	public void setTitle(String title) {
		link.add(new AttributeModifier("title", true, new Model(title)));
 

	}

	public OwnAjaxLink getLink() {
		return link;
	}

	public void addOwnListener(OwnListener listener) {
		listenerSet.add(listener);
	}

	public void removeOwnListener(OwnListener listener) {
		listenerSet.remove(listener);
	}

	public void setLink(OwnAjaxLink link) {
		this.link = link;
	}

}
